package cn.kgc.controller;

import cn.kgc.client.OrderClient;
import cn.kgc.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/4/20
 * @Description:
 */
@RequestMapping("user")
@RestController
public class UserController {

    @Autowired
    private OrderClient orderClient;

    @RequestMapping("m1")
    public String method1(){
        return " user ok";
    }

    @RequestMapping("m2")
    public String method2(){
        //  1.根据orderClient 配置的 服务名称 拉取通信节点  uri  2. method2() RequestMapping("/order/m2")  -> uri+/order/m2
        String s = orderClient.method2();
        return " user ok " +s;
    }


    @RequestMapping("m3")
    public  List<Order> method3(String username){
        List<Order> orders = orderClient.method3(username);
        return orders;
    }


    @RequestMapping("m4")
    public  Order method4(Integer id){
        Order order = orderClient.method4(id);
        System.out.println("order = " + order);
        return order;
    }


    @RequestMapping("m5")
    public  String method5(Order order){
        System.out.println("order = " + order);
        String s = orderClient.method5(order.getUsername(),order.getId(),order.getProductName());
        return s ;
    }


    @RequestMapping("m6")
    public  String method6(Order order){   // json

        System.out.println("order = " + order);
        String s = orderClient.method6(order);
        return s ;
    }
}
